

<script type="text/javascript">
	$(function() {
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		$("#dialog").dialog("destroy");
		
		var email = $("#email"),

			allFields = $([]).add(email),
			tips = $(".validateTips");

		function updateTips(t) {
			tips
				.text(t)
				.addClass('ui-state-highlight');
			setTimeout(function() {
				tips.removeClass('ui-state-highlight', 1500);
			}, 500);
		}

		function checkLength(o,n,min,max) {

			if ( o.val().length > max || o.val().length < min ) {
				o.addClass('ui-state-error');
				updateTips("Length of " + n + " must be between "+min+" and "+max+".");
				return false;
			} else {
				return true;
			}

		}

		function checkRegexp(o,regexp,n) {

			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass('ui-state-error');
				updateTips(n);
				return false;
			} else {
				return true;
			}

		}

		function checkEmailRecoverPassword(email){
			//alert(email);
			$.ajax({
				type: "GET",
				url: 'home/checkEmailRecoverPassword',
				async:false,
				dataType: 'text',
				data: "email=" + email,
				success: function(data) {
					$aux = data;
					if($aux=="0"){
						//alert($aux);
						updateTips("Aucun nom d'usuaire est incrit sur cet address");
					}
					
				}
			});
			if($aux=="1"){
				//alert("pasa por true")
				return true;
			}else{
				return false;
			}
		}
		
		$("#dialog-form").dialog({
			autoOpen: false,
			height: 200,
			width: 350,
			modal: true,
			buttons: {
				'Obtenir votre mot de passe': function() {
					var bValid = true;
					allFields.removeClass('ui-state-error');

					bValid = bValid && checkLength(email,"email",6,80);


					// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
					 checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"SVP, tapez un email correct, eg. jacquesp@gmail.com");
				bValid = bValid && checkEmailRecoverPassword(email.val());
					
					
					if (bValid) {
						$('#users tbody').append('<tr>' +
							'<td>' + email.val() + '</td>' + 
							'</tr>'); 
							$(".ui-dialog-buttonpane").remove();
							$("#recoverPsswdForm").remove();
							$("#signin_username").val(email.val());
							updateTips("Nous venons d'envoyer un email a votre address "+email.val()+" avec votre nouveau password.");
							//alert("es valido, ahora te enviamos por cooreo");
						//$(this).dialog('close');
						
					}
				},
				'Fermer': function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				allFields.val('').removeClass('ui-state-error');
			}
		});

		$('#create-user').click(function() {
				$('#dialog-form').dialog('open');
		});

	});
	</script>
	
	<div id="dialog-form" title="Tapez votre &eacute;mail d'inscription et nous vous reenverrons un nouveau mot de passe">
	<p class="validateTips">Tapez votre &eacute;mail</p>
	<form id="recoverPsswdForm">
		<input type="text" name="email" id="email" value="" size="50" class="recoverPsswdFormInput text ui-widget-content ui-corner-all" />
	</form>
</div>

<div id="breadcrumbs"><?php echo link_to('Accueil', '@homepage') ?> > Votre compte </div>
<div class="post">
<h1>Votre compte &agrave; un click</h1>
<blockquote><p>Ne perdez pas de vue votre <strong>logements favoris</strong>. Si vous voulez les r&eacute;cup&eacute;rer dans une prochaine visite loguez vous. Si c'est la premi&egrave;re fois <strong><?php echo link_to('cliquez ici pour vous inscrire', '@enregistrez_vous') ?></strong>.</p></blockquote>	

<form action="<?php echo url_for('user/signin') ?>" method="POST" class="formSignIn">
  <table>
    <tr>
	<td><?php echo $form['username']->renderLabel() ?></td>
	<td><?php echo $form['username']->render() ?></td>
	<td> <?php echo $form['username']->renderError() ?></td>
	</tr>
	
	<tr>
	<td><?php echo $form['password']->renderLabel() ?></td>
	<td><?php echo $form['password']->render() ?></td>
	<td> <?php echo $form['password']->renderError() ?></td>
	</tr>
	
	<tr>
	<td colspan="3"><?php echo $form['ajouterFavorites']->render() ?><?php echo $form['ajouterFavorites']->renderLabel() ?></td>
	</tr>
    
	<?php echo $form['_csrf_token'] ?>
    <tr>
      <td colspan="3">
        <input type="submit" value="Valider"/>
      </td>
    </tr>
  </table>
</form>


<h3><p><a style="" href="#" id="create-user">J'ai oubli&eacute; mon mot de passe</a></p></h3>
 </div>